﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CCF20Model;
using WiseLink.RDS.Resource;
namespace CCF20Model.FaultHandler
{
    public class GiveUpCustomerFaultHandler : FaultHandlerBase
    {
        public GiveUpCustomerFaultHandler(IFaultHandler faultHandler)
        {
            this.PreviousHandler = faultHandler;
            this.MyVehicle = faultHandler.MyVehicle;
            this.MyFault = faultHandler.MyFault;
            this.ccf20Ent = faultHandler.ccf20Ent;
        }
        public override void ProcessRequest()
        {
            IFaultHandler nextHandler;
            if (MyFault.FaultType.Contains(WiseLinkRDSStatus.Fault_Type_Urgent))
            {
                VehicleRepairHistory vrh = MyVehicle.VehicleRepairHistories.OrderByDescending(r => r.OutShopDate).FirstOrDefault();
                Fault crashfault = vrh.Faults.Where(f => f.FaultType.Contains(WiseLinkRDSStatus.Fault_Type_Urgent) && f.CloseReason != "排除急救").FirstOrDefault();
                if (crashfault != null)
                {
                    CloseFault(MyVehicle.LastContactResult);
                    LoggerHelper.LogZICDebug("[放弃客户]-撞车请求-放弃客户时包括撞车-屏蔽撞车请求");
                    nextHandler = new CompleteFaultHandler(this);
                }
                else
                {
                    LoggerHelper.LogZICDebug("[放弃客户]-撞车请求-放弃客户时不包括撞车-显示撞车请求");
                    nextHandler = new ProcessUrgentHandler(this);
                }
            }
            else
            {
                CloseFault(MyVehicle.LastContactResult);
                LoggerHelper.LogZICDebug(string.Format("[放弃客户]屏蔽所有非撞车请求 当前请求为{0}",MyFault.FaultType));
                nextHandler = new CompleteFaultHandler(this);
                
            }
            nextHandler.ProcessRequest();
        }
    }
  
}
